﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharedLib.DataStructure;

namespace SharedLib.DataAccess
{
    /// <summary>
    /// The interface of data provider
    /// A data provider is used to retrieve data from a data source and to reconcile changes back to the data source.
    /// </summary>
    public interface IDataModelProvider<T> where T : IDataModel
    {
        /// <summary>
        /// Occurs when items are changed in the data source
        /// </summary>
        event EventHandler<GenericEventArgs<IList<DataChangeSet<T>>>> ItemsChanged;
        /// <summary>
        /// Occurs when item are added to the data source
        /// </summary>
        event EventHandler<GenericEventArgs<IList<T>>> ItemsAdded;
        /// <summary>
        /// Occurs when items are removed from the data source
        /// </summary>
        event EventHandler<GenericEventArgs<IList<T>>> ItemsRemoved;

        /// <summary>
        /// Get all items from the data source
        /// </summary>
        /// <returns></returns>
        List<T> GetItems();

        /// <summary>
        /// Get the item that matching the giving condition
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        T GetItem(IQueryCondition<T> condition);

        /// <summary>
        /// Add an item to the data source
        /// </summary>
        /// <param name="item"></param>
        void AddItem(T item);

        /// <summary>
        /// Add items to the data source
        /// </summary>
        /// <param name="item"></param>
        void AddItems(IList<T> item);

        /// <summary>
        /// Update an item in the data source
        /// </summary>
        /// <param name="oldItem"></param>
        /// <param name="newItem"></param>
        void UpdateItem(T oldItem, T newItem);

        /// <summary>
        /// Update items the data source
        /// </summary>
        /// <param name="changes"></param>
        void UpdateItems(IList<DataChangeSet<T>> changes);

        /// <summary>
        /// Remove an item from the data source
        /// </summary>
        /// <param name="item"></param>
        void RemoveItem(T item);

        /// <summary>
        /// Remove items from the data source
        /// </summary>
        /// <param name="items"></param>
        void RemoveItems(IList<T> items);

        /// <summary>
        /// Save the changes
        /// </summary>
        void Save();
    }
}
